package dal

import (
	"context"
	"github.com/cloudwego/hertz/pkg/common/hlog"
	"mall_frontend_api/biz/config"
	"mall_frontend_api/biz/model"
)

func (c *ProductSpecDAO) MGetByProductIDs(ctx context.Context, productIDs []int64) (map[int64]map[int64]*model.ProductSpec, error) {
	list, err := ProductSpec.WithContext(ctx).Where(
		ProductSpec.BizID.Eq(config.Values.BizID),
		ProductSpec.ProductID.In(productIDs...),
	).Find()
	if err != nil {
		hlog.CtxErrorf(ctx, "dal.MGetProductSpecByProductIDs err: %v", err)
		return nil, err
	}
	var data = make(map[int64]map[int64]*model.ProductSpec)
	for _, info := range list {
		if _, ok := data[info.ProductID]; ok {
			data[info.ProductID][info.ID] = info
		} else {
			data[info.ProductID] = map[int64]*model.ProductSpec{info.ID: info}
		}
	}
	return data, nil
}
